package com.qf.hospital.mapper;

import com.qf.hospital.entity.SysMenu;
import com.qf.hospital.entity.SysUser;
import com.qf.hospital.entity.SysUserExample;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface SysUserMapper {
    long countByExample(SysUserExample example);

    int deleteByExample(SysUserExample example);

    int deleteByPrimaryKey(Integer userId);

    int insert(SysUser record);

    int insertSelective(SysUser record);

    List<SysUser> selectByExample(SysUserExample example);

    SysUser selectByPrimaryKey(Integer userId);

    int updateByExampleSelective(@Param("record") SysUser record, @Param("example") SysUserExample example);

    int updateByExample(@Param("record") SysUser record, @Param("example") SysUserExample example);

    int updateByPrimaryKeySelective(SysUser record);

    int updateByPrimaryKey(SysUser record);

    /**
     * 根据用户id查询菜单信息
     * @param userId
     * @return
     */
    List<SysMenu> findMenuByUserId(@Param("userId")Integer userId);

    /**
     * 查询当前用户拥有的角色is
     * @param userid
     * @return
     */
    @Select("select ur.rid from sys_user u inner join sys_role_user ur on u.user_id = ur.uid where u.user_id = #{userId} and u.available = 1")
    List<Integer> findUserRoleIdByUserId(@Param("userId") Integer userid);

    /**
     * 删除用户的全部角色
     * @param userid
     */
    @Delete("delete from sys_role_user where uid = #{userId}")
    void deleteUserRoleByUserId(@Param("userId") Integer userid);


    /**
     * 添加用户的角色
     * @param userid
     * @param ids
     * @return
     */
    int saveUserRole(@Param("userId") Integer userid, @Param("roleIds") Integer[] ids);

}